package cn.lingyangwl.agile.system;

import cn.lingyangwl.agile.model.constants.*;
import cn.lingyangwl.agile.model.module.auth.*;
import cn.lingyangwl.agile.model.module.config.*;
import cn.lingyangwl.agile.system.model.entity.*;
import cn.lingyangwl.agile.system.model.rqrs.accesskey.*;
import cn.lingyangwl.agile.system.model.rqrs.log.*;
import cn.lingyangwl.agile.system.model.rqrs.tenant.*;
import cn.lingyangwl.agile.system.model.rqrs.user.*;
import cn.lingyangwl.framework.core.response.*;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author shenguangyang
 */
@Lazy
@FeignClient(contextId = "remoteSystemService", url = "${server-url:}", value = ServiceCodeCons.SYSTEM_SERVICE)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
public interface RemoteSystemService {
    @GetMapping(value = "/accessKey/getAccessKeyBySecretId", headers = SecurityCons.HEADER_FROM_IN)
    Resp<AccessKeyResp> getAccessKeyBySecretId(@RequestParam(value = "secretId") String secretId);

    @GetMapping(value = "/accessKey/getAccessKeyById", headers = SecurityCons.HEADER_FROM_IN)
    Resp<AccessKeyResp> getAccessKeyById(@RequestParam(value = "id") Long id);

    /**
     * 通过账号查询用户信息
     *
     * @return 结果
     */
    @PostMapping(value = "/user/getLoginUser", headers = SecurityCons.HEADER_FROM_IN)
    Resp<LoginUser> getLoginUser(@RequestBody LoginUserGetReq req);

    @PostMapping(value = "/user/save", headers = SecurityCons.HEADER_FROM_IN)
    Resp<Long> saveUser(UserSaveReq req);

    @DeleteMapping(value = "/user/delete", headers = SecurityCons.HEADER_FROM_IN)
    Resp<?> removeUserById(@RequestParam(value = "id") Long userId);

    @GetMapping(value = "/user/delete", headers = SecurityCons.HEADER_FROM_IN)
    Resp<List<UserResp>> listUser(UserPageReq query);

    @GetMapping(value = "/user/getById", headers = SecurityCons.HEADER_FROM_IN)
    Resp<UserResp> getUserById(@RequestParam(value = "id") Long userId);

    @PostMapping(value = "/user/deleteLoginUser", headers = SecurityCons.HEADER_FROM_IN)
    Resp<?> deleteLoginUser(LoginUserDeleteReq req);

    @GetMapping(value = "/user/listUserByIds", headers = SecurityCons.HEADER_FROM_IN)
    Resp<List<UserResp>> listUserByIds(@RequestParam(value = "userIds") List<Long> userIds);

    @GetMapping("/user/getUserByAccount")
    Resp<SysUser> getUserByAccount(@RequestParam("account") String account);

    @PostMapping(value = "/tenant/save", headers = SecurityCons.HEADER_FROM_IN)
    Resp<String> saveTenant(TenantSaveReq req);

    @DeleteMapping(value = "/tenant/delete", headers = SecurityCons.HEADER_FROM_IN)
    Resp<?> deleteTenant(@RequestParam("id") String tenantId);

    @PostMapping(value = "/tenant/update", headers = SecurityCons.HEADER_FROM_IN)
    Resp<?> updateTenant(TenantUpdateReq req);

    @PostMapping(value = "/user/profile/initTenant", headers = SecurityCons.HEADER_FROM_IN)
    Resp<?> initTenant();

    @GetMapping(value = "/tenant/getMgtSceneTenantId")
    Resp<String> getMgtSceneTenantId(@RequestParam("tenantId") String tenantId);

    @GetMapping(value = "/tenant/getMainTenantId")
    Resp<String> getMainTenantId(@RequestParam("tenantId") String tenantId);

    @ApiOperation(value = "获取使用的配置")
    @GetMapping("/config/getUseConfig")
    Resp<ConfigInfo> getUseConfig(@RequestParam("configDefine") String configDefine);


    /**
     * 获取角色权限(忽略租户)
     * @param roleIds 角色id
     * @return key: 模块名, key: 可访问的资源路径集合
     */
    @GetMapping("/role/listAssignUrl")
    Resp<Map<String, List<String>>> listAssignRoleUrl(@RequestParam("roleIds") List<Long> roleIds);

    @GetMapping("/area/listAreaByNames")
    Resp<List<SysArea>> listAreaByNames(@RequestParam("areaTypes") List<String> areaTypes,
                                        @RequestParam("areaNames") List<String> areaNames);

    @GetMapping("/tenant/listTenantByIds")
    Resp<List<TenantResp>> listTenantByIds(@RequestParam("tenantIds") List<String> tenantIds);

    @Operation(summary = "分页租户数据(内部专用)")
    @GetMapping(value = "/tenant/pageTenantFromInside")
    Resp<List<SysTenant>> pageTenant(@RequestParam("pageNum") Integer pageNum,
                                     @RequestParam("pageSize") Integer pageSize);

    @ApiOperation("定时删除日志")
    @PostMapping("/accessLog/deleteLogTask")
    Resp<Integer> deleteAccessLog(@RequestParam("endTime") String endTime);
}
